Conversation
|
|
||
|
|
||
| // Compute the target sum by parsing twice the integer array | ||
| // FindIntruder the target sum by parsing twice the integer array |
Collaborator
There was a problem hiding this comment.
That's not the name of the func
| c.updatePreamble(idxStartPreamble, idxEndPreamble) | ||
| idxStartPreamble++ | ||
| } | ||
| // should not happened |
Collaborator
There was a problem hiding this comment.
Suggested change
| // should not happened | |
| // should not happen |
| return 0, 0 | ||
| } | ||
|
|
||
| // findPair returns the odd value if there is no pair summing it |
| for p := range c.Preamble { | ||
| toFind := elt - p | ||
|
|
||
| f := math.Abs(float64(toFind)) |
Collaborator
There was a problem hiding this comment.
or you could write your own abs func
| // remove the first element | ||
| delete(c.Preamble, c.Numbers[idxToRemove]) | ||
| // add the next element | ||
| c.Preamble[c.Numbers[idxToRemove+idxPreamble]] = struct{}{} |
Collaborator
There was a problem hiding this comment.
i supppose this will always work, but is there any safety net somewhere? c.Numbers is an array, after all.
| if err != nil { | ||
| return elt, err | ||
| } | ||
| return elt, nil |
Collaborator
There was a problem hiding this comment.
so, basically, always return elt, err ?
in the end, always return srconv.Atoi(line)?
| for sum > target { | ||
| sum -= tmpArray[0] | ||
| s := tmpArray[1:] | ||
| tmpArray = s |
Collaborator
There was a problem hiding this comment.
or tmpArray = tmpArray[1:]
|
|
||
| // sumMinMax returns the sum of the min and max values from a given array | ||
| func sumMinMax(sum []int) int { | ||
| min, max := sum[0], 0 |
Collaborator
There was a problem hiding this comment.
it's better to also initialise max to sum[0]. just in case you encounter negative numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.